/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package firstround2009;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import static chanlib.Chan_IO.*;

/**
 * @author robit
 * 00:52:03 had been taken to work this problem out!!
 */
public class AllYourBase{
    /*
      All neccesary to be defined
      including:
      variable, inner class
    */
    // static int A;
    // static void B();
    // static class C

    /*
       One calculation fits all of the cases.
    */
    static void preReckon(){
        return;
    }

    /*
      calculate the answer
    */
    private static void reckon(int line) {
        char msg[]=String().toCharArray();       
        HashMap<Character,Integer> mp=new HashMap<Character, Integer>();
        int base=2;
        mp.put(msg[0],1);
        int nxt=0;
        while(nxt<msg.length&&msg[nxt]==msg[0])nxt++;
        if(nxt<msg.length)mp.put(msg[nxt], 0);

        for(int c=nxt+1;c<msg.length;c++)
        {
            if(!mp.containsKey(msg[c])){
                mp.put(msg[c],base++);
            }
        }
        long ans=mp.get(msg[0]);
        for(int c=1;c<msg.length;c++){
            ans=ans*base+mp.get(msg[c]);
        }

        String output=String.format("Case #%d: %d",line,ans);
        writeln(output, OUTFILE);
        //writeln(String.format("N=%d K=%d\n%s", N, K, ans),ANALFILE);
        //println(output);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        /*
           Pre-computing for all cases
        */

        // Just in case!
        //preReckon();
        //while((char)read()!='P');

        /*
          Input-output
        */
        boolean test=false;
        boolean small=false;
        String prob="A";
        String filename;
        if(test) filename="test";
        else{
            if(small) filename=prob+"-small-practice";
            else filename=prob+"-large-practice";
        }
        try {
            /*
               Init IO,plus determination of input line number
             */
            int lineNums = initFileIO(filename);
            for (int i = 1; i <= lineNums; i++) {
                reckon(i);
            }
        } finally {
            endIO();
        }
    }

}
